package com.atcc.test.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options.FlushCachePolicy;
import org.apache.ibatis.annotations.Param;

import com.atcc.test.pojo.BasicUser;

@Mapper
public interface UserMapper {

	/**
	 * 查询所有用户BasicUser
	 * @return
	 */
	@Select("select * from user")
	@Results({
		@Result(column="user_money",property="userMoney"),
		@Result(column="user_name",property="userName"),
		@Result(column="user_level",property="userLevel"),
		@Result(column="user_password",property="userPassword"),
		@Result(column="user_id",property="userId"),
	})
	List<BasicUser> queryAllBasicUser();
	
	/**
	 * 增加一个用户BasicUser
	 * @param basicUser
	 */
	@Insert("insert into user(user_name, user_money, user_level, user_password)"
			+ " values(#{basicUser.userName}, #{basicUser.userMoney}, #{basicUser.userLevel},"
			+ " #{basicUser.userPassword})")
	@Options(flushCache=FlushCachePolicy.TRUE)
	void saveBasciUser(@Param("basicUser") BasicUser basicUser);
	
	/**
	 * 根据名字查询单个用户BasicUser
	 * @param userName
	 * @return
	 */
	@Select("select * from user where user_name = #{userName}")
	@Results({
		@Result(column="user_money",property="userMoney"),
		@Result(column="user_name",property="userName"),
		@Result(column="user_level",property="userLevel"),
		@Result(column="user_password",property="userPassword"),
		@Result(column="user_id",property="userId"),
	})
	BasicUser queryBasicUserByUserName(@Param("userName") String userName);
	
	@Select("select * from user where user_id = #{userId}")
	@Results({
		@Result(column="user_money",property="userMoney"),
		@Result(column="user_name",property="userName"),
		@Result(column="user_level",property="userLevel"),
		@Result(column="user_password",property="userPassword"),
		@Result(column="user_id",property="userId"),
	})
	BasicUser queryBasicUserByUserId(@Param("userId") int userId);
	
	
}
